package quick.portal.fragment.home;

import java.util.List;

import com.alibaba.fastjson.JSONArray;

import quick.common.AppContext;
import quick.portal.R;
import quick.portal.activity.WebviewActivity;
import quick.portal.data.SystemInfo;
import quick.portal.fragment.DataListFragment;
import quick.view.quickadapter.BaseAdapterHelper;
import android.content.Intent;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.TextView;


public class HomeAppFragment extends DataListFragment<SystemInfo> {
	
	public HomeAppFragment() {
		this.queryAction = "SystemInfoList";
    	this.itemViewLayoutId = R.layout.data_list_item_home_app;
	}
    
	@Override
	protected void adapterConvert(BaseAdapterHelper helper, SystemInfo app) {
		helper.setText(R.id.name, app.getName())
        .setTag(R.id.name, app.getUrl());
	}

	@Override
	protected void showDetail(View view) {
		TextView tvName = (TextView)view.findViewById(R.id.name);
    	String url = tvName.getTag().toString();
    	
    	String token = AppContext.getInstance().getToken();
    	url = url + "?" + AppContext.Login_Token_Key + "=" + token;

        Intent intent = new Intent(context,WebviewActivity.class);
        intent.putExtra("Url", url);
        startActivity(intent);
	}

	@Override
	protected List<SystemInfo> parseArray(String body) {
		List<SystemInfo> list = JSONArray.parseArray(body, SystemInfo.class);
		
		return list;
	}
	
	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
		
		if(isVisibleToUser)
		{
			PopupMenu menu = this.GetOriginalPopupMenu();
			//menu.getMenu().add(0,WorkOrderFragment.menu_addworkorder,1,"新建工单");
			menu.setOnMenuItemClickListener(this);
		}
	}

}
